<template>
  <div>
    <FormPanel ref="from" :list="formList" @formChange="changeHandle" :isSubmitBtn="false" :collapse="false" labelWidth="110" />


    <div style="height:47px;"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDrawer(1)">关 闭</el-button>
      <!-- <el-button @click="closeDrawer(2)" type="primary">保 存</el-button> -->
      <multiuse-button type="primary" :click="closeDrawer.bind(this, 2)">保 存</multiuse-button>
    </div>
  </div>
</template>
<script>
import {getList,getDetail,postSave} from '@/api/dealerSale/InventoryManagement/WarehouseMaintenance/index.js'
import { dictionary } from '@/utils/dictMixin';
export default {
  data(){
    this.saveData=null;
    return{
      formList:this.createdFrom(),
    }
  },
  components: {
  },
  props:['rowData'],
  created(){
    this.getDetail(this.rowData)
  },
  mixins:[dictionary],
  methods:{
    createdFrom(){
      return [
        {
          type: 'INPUT',
          label: '仓库代码',
          fieldName: 'warehouseCode',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'INPUT',
          label: '仓库名称',
          fieldName: 'warehouseName',
          placeholder: '请输入',
          rules: [{ required: true, message: '请输入', trigger: 'blur' }],
        },
        {
          type: 'SELECT',
          label: '仓库类型',
          fieldName: 'warehouseType',
          placeholder: '请选择',
          itemList:this.createDictList('6009')||[],

        },
        {
          type: 'SELECT',
          label: '状态',
          fieldName: 'status',
          placeholder: '请选择',
          itemList:this.createDictList('1003')||[],
          initialValue:10031001
        },
        {
          type: 'INPUT',
          label: '备注',
          fieldName: 'remark',
          selfCols:3
        },

      ]
    },
    async getDetail(data){
      let res=await getDetail({id:data.warehouseId})
      for (let i in res.data) {
      this.formList.map(x => {
          if (i == x.fieldName) {
            x.initialValue = res.data[i];
          }
        });
      }
    },
    changeHandle(val){
      this.saveData=val;
    },

    async closeDrawer(type){
      if(type==1){
        this.$emit('close')
      }else{
        this.$refs.from.SUBMIT_FORM();
        console.log(this.saveData, 'this.saveData');
        if (this.saveData) {
          let json = JSON.parse(JSON.stringify(this.saveData));
          json.warehouseId=this.rowData.warehouseId;
          let res = await postSave(json);
          if (res.resultCode == 200) {
            this.$notify({
              title: '成功',
              message: '保存成功',
              type: 'success'
            });
            this.$emit('close', json);
          }else{
            this.saveData=null;
          }
        }

      }
    }

  }
}
</script>
